From deb5f9442abf30ded172eb96cd600c7339b7ea9e Mon Sep 17 00:00:00 2001 From: "mjw@wray-m-3.hpl.hp.com" Date: Tue, 27 Jul 2004 12:26:33 +0000 Subject: [PATCH] bitkeeper revision 1.1108.14.6 (410649f9zyS54Re8bSXNwM_nPxqrOw) Add support for setting and getting domain maxmem. --- tools/libxc/xc_domain.c | 2 +- tools/python/xen/lowlevel/xc/xc.c | 11 ++++++----- tools/python/xen/xend/XendClient.py | 8 +++++--- tools/python/xen/xend/XendDomain.py | 11 +++++++++++ tools/python/xen/xend/XendDomainInfo.py | 13 +++++++------ tools/python/xen/xend/server/SrvDomain.py | 7 +++++++ tools/python/xen/xm/main.py | 18 +++++++++++++++++- 7 files changed, 54 insertions(+), 16 deletions(-) diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 838418e0b7..d389757cee 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -105,7 +105,7 @@ int xc_domain_getinfo(int xc_handle, DOMFLAGS_SHUTDOWNMASK; info->nr_pages = op.u.getdomaininfo.tot_pages; - info->max_memkb = op.u.getdomaininfo.max_pages<<(PAGE_SHIFT-10); + info->max_memkb = op.u.getdomaininfo.max_pages<<(PAGE_SHIFT); info->shared_info_frame = op.u.getdomaininfo.shared_info_frame; info->cpu_time = op.u.getdomaininfo.cpu_time; strncpy(info->name, op.u.getdomaininfo.name, XC_DOMINFO_MAXNAME); diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index 6e55853360..21d40b026e 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -906,15 +906,15 @@ static PyObject *pyxc_domain_setmaxmem(PyObject *self, XcObject *xc = (XcObject *)self; u32 dom; - unsigned long max_memkb; + unsigned long maxmem_kb; - static char *kwd_list[] = { "dom", "max_memkb", NULL }; + static char *kwd_list[] = { "dom", "maxmem_kb", NULL }; if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list, - &dom, &max_memkb) ) + &dom, &maxmem_kb) ) return NULL; - if ( xc_domain_setmaxmem(xc->xc_handle, dom, max_memkb) != 0 ) + if ( xc_domain_setmaxmem(xc->xc_handle, dom, maxmem_kb) != 0 ) return PyErr_SetFromErrno(xc_error); Py_INCREF(zero); @@ -980,6 +980,7 @@ static PyMethodDef pyxc_methods[] = { " blocked [int]: Bool - is the domain blocked waiting for an event?\n" " running [int]: Bool - is the domain currently running?\n" " mem_kb [int]: Memory reservation, in kilobytes\n" + " maxmem_kb [int]: Maximum memory limit, in kilobytes\n" " cpu_time [long]: CPU time consumed, in nanoseconds\n" " name [str]: Identifying name\n" " shutdown_reason [int]: Numeric code from guest OS, explaining " @@ -1228,7 +1229,7 @@ static PyMethodDef pyxc_methods[] = { METH_VARARGS | METH_KEYWORDS, "\n" "Set a domain's memory limit\n" " dom [int]: Identifier of domain.\n" - " max_memkb [long]: .\n" + " maxmem_kb [long]: .\n" "Returns: [int] 0 on success; -1 on error.\n" }, { NULL, NULL, 0, NULL } diff --git a/tools/python/xen/xend/XendClient.py b/tools/python/xen/xend/XendClient.py index 8e8b2ba56d..3846fbce76 100644 --- a/tools/python/xen/xend/XendClient.py +++ b/tools/python/xen/xend/XendClient.py @@ -510,6 +510,11 @@ class Xend: 'latency' : latency, 'xtratime': xtratime }) + def xend_domain_maxmem_set(self, id, memory): + return self.xendPost(self.domainurl(id), + { 'op' : 'maxmem_set', + 'memory' : memory }) + def xend_domain_vifs(self, id): return self.xendGet(self.domainurl(id), { 'op' : 'vifs' }) @@ -565,9 +570,6 @@ class Xend: {'op' : 'inject', 'event' : fileof(sxpr) }) - def xend_dmesg(self): - return self.xendGet(self.dmesgurl()) - def xendmain(srv, asynch, fn, args): if asynch: client = AsynchXendClientProtocol() diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py index 6f2ac91928..1e6a91a244 100644 --- a/tools/python/xen/xend/XendDomain.py +++ b/tools/python/xen/xend/XendDomain.py @@ -686,6 +686,17 @@ class XendDomain: dom = int(dom) return xc.shadow_control(dom, op) + def domain_maxmem_set(self, dom, mem): + """Set the memory limit for a domain. + + @param dom: domain + @param mem: memory limit (in MB) + @return: 0 on success, -1 on error + """ + dom = int(dom) + maxmem = int(mem) * 1024 + return xc.domain_setmaxmem(dom, maxmem_kb = maxmem) + def instance(): """Singleton constructor. Use this instead of the class constructor. diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index d855e8b005..9d7dfe325c 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -408,12 +408,13 @@ class XendDomainInfo: ['memory', self.memory] ] if self.info: - run = (self.info['running'] and 'r') or '-' - block = (self.info['blocked'] and 'b') or '-' - stop = (self.info['paused'] and 'p') or '-' - susp = (self.info['shutdown'] and 's') or '-' - crash = (self.info['crashed'] and 'c') or '-' - state = run + block + stop + susp + crash + sxpr.append(['maxmem', self.info['maxmem_kb']/1024 ]) + run = (self.info['running'] and 'r') or '-' + block = (self.info['blocked'] and 'b') or '-' + pause = (self.info['paused'] and 'p') or '-' + shut = (self.info['shutdown'] and 's') or '-' + crash = (self.info['crashed'] and 'c') or '-' + state = run + block + pause + shut + crash sxpr.append(['state', state]) if self.info['shutdown']: reason = shutdown_reason(self.info['shutdown_reason']) diff --git a/tools/python/xen/xend/server/SrvDomain.py b/tools/python/xen/xend/server/SrvDomain.py index 8eb5e12719..886021ee75 100644 --- a/tools/python/xen/xend/server/SrvDomain.py +++ b/tools/python/xen/xend/server/SrvDomain.py @@ -151,6 +151,13 @@ class SrvDomain(SrvDir): val = fn(req.args, {'dom': self.dom.id}) return val + def op_maxmem_set(self, op, req): + fn = FormFn(self.xd.domain_maxmem_set, + [['dom', 'int'], + ['memory', 'int']]) + val = fn(req.args, {'dom': self.dom.id}) + return val + def op_vifs(self, op, req): return self.xd.domain_vif_ls(self.dom.id) diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py index 0e86572ed1..d282193c43 100644 --- a/tools/python/xen/xm/main.py +++ b/tools/python/xen/xm/main.py @@ -351,6 +351,22 @@ class ProgPincpu(Prog): xm.prog(ProgPincpu) +class ProgMaxmem(Prog): + group = 'domain' + name = 'maxmem' + info = """Set domain memory limit.""" + + def help(self, args): + print args[0], "DOM MEMORY" + print "\nSet the memory limit for domain DOM to MEMORY megabytes." + + def main(self, args): + if len(args) != 3: self.err("%s: Invalid argument(s)" % args[0]) + v = map(int, args[1:3]) + server.xend_domain_maxmem_set(*v) + +xm.prog(ProgMaxmem) + class ProgBvt(Prog): group = 'scheduler' name = "bvt" @@ -529,7 +545,7 @@ class ProgDmesg(Prog): info = """Print Xen boot output.""" def main(self, args): - print server.xend_dmesg()[1] + print server.xend_node_dmesg()[1] xm.prog(ProgDmesg) -- 2.30.2